/*
 * @Author: Luo jiaxing 
 * @Date: 2017-05-23 16:07:07 
 * @Last Modified by: Luo jiaxing
 * @Last Modified time: 2017-06-15 19:08:48
 */
Ext.define('Admin.view.needWater.waterSitAnalysis.WaterSitAnalysisController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.waterSitAnalysisController',
    views: ['Admin.view.needWater.waterSitAnalysis.WaterSitAnalysis'],
    insertView: false,
    init: function () {
        var me = this;
    },
    insertView: function (dom) {
        var me = this;
        var $ele = $('#' + dom.el.id).find('.x-panel-header');
        var style = 'style="position: absolute;top: 15px; right: 15px;cursor: pointer;color: #F0F0EC;text-decoration: none;"';
        $ele.append('<a class="modalChart" ' + style + '>查看</a>');
        $('.modalChart').on('click', function () {
            if ($('#szyxsModalChart').length <= 0) {
                me.viewProcess('洪门水库下灌水量过程');
            }
        });
    },
    buildszyxsChart1: function (dom) {
        var me = this;
        var data = {
            title: '洪门水库运行过程',
            domId: dom.el.id + '-body',
            data: [{
                name: '计划期末蓄水量',
                data: [160, 160, 160, 170, 170, 165, 140, 110, 100, 90, 85, 95],
                dashStyle: 'dash'
            }, {
                name: '实际期末蓄水量',
                data: [155, 150, 130, 135]
            }, {
                name: '兴利库容',
                data: [null, null, null, null, 170, 170, 170, 170, 170, 170, 170, 170],
                dashStyle: 'dash',
                marker: {
                    radius: 0
                }
            }, {
                name: '农业限制线',
                data: [110, 130, 130, 115, 115, 115, 115, 115, 110, 110, 110, 110],
                dashStyle: 'dash',
                marker: {
                    radius: 0
                }
            }, {
                name: '工业限制线',
                data: [65, 65, 65, 65, 70, 70, 70, 70, 70, 70, 70, 70],
                dashStyle: 'dash',
                marker: {
                    radius: 0
                }
            }]
        };
        me.chartInit(data.domId, data.title, data.data);
    },
    buildszyxsChart2: function (dom) {
        var me = this;
        var data = {
            title: '廖坊水库运行过程',
            domId: dom.el.id + '-body',
            data: [{
                name: '计划期末蓄水量',
                data: [160, 160, 160, 170, 170, 165, 140, 110, 100, 90, 85, 95],
                dashStyle: 'dash'
            }, {
                name: '实际期末蓄水量',
                data: [155, 150, 130, 135]
            }, {
                name: '兴利库容',
                data: [null, null, null, null, 170, 170, 170, 170, 170, 170, 170, 170],
                dashStyle: 'dash',
                marker: {
                    radius: 0
                }
            }, {
                name: '农业限制线',
                data: [110, 130, 130, 115, 115, 115, 115, 115, 110, 110, 110, 110],
                dashStyle: 'dash',
                marker: {
                    radius: 0
                }
            }, {
                name: '工业限制线',
                data: [65, 65, 65, 65, 70, 70, 70, 70, 70, 70, 70, 70],
                dashStyle: 'dash',
                marker: {
                    radius: 0
                }
            }]
        };
        me.chartInit(data.domId, data.title, data.data);
    },
    // 查看运行过程
    viewProcess: function (title) {
        var me = this;
        Ext.create('Ext.window.Window', {
            title: title,
            width: 700,
            height: 350,
//          modal: true,
            layout: 'fit',
            items: [{
                html: '<div class="tab-inner-content-chart row">' +
                '<div class="col-md-12" style="padding: 0;"><div id="szyxsModalChart"></div></div>' +
                '</div>'
            }],
            listeners: {
                afterrender: function () {
                    var data = [{
                        name: '计划下灌',
                        data: [60, 90, 140, 100, 78, 43, 35, 30, 33, 34, 37, 45],
                        dashStyle: 'dash'
                    }, {
                        name: '实际下灌',
                        data: [58, 88, 120, 85]
                    }];
                    setTimeout(function () {
                        $('#szyxsModalChart').highcharts({
                            title: {
                                text: ''
                            },
                            // chart: {
                            //     marginLeft: 40
                            // },
                            xAxis: {
                                categories: ['6月', '7月', '8月', '9月', '10月', '11月', '12月', '1月', '2月', '3月', '4月', '5月']
                            },
                            yAxis: {
                                title: {
                                    text: '水量/亿m³'
                                },
                                plotLines: [{
                                    value: 0,
                                    width: 1,
                                    color: '#808080'
                                }]
                            },
                            tooltip: {
                                valueSuffix: '亿m³'
                            },
                            legend: {
                                layout: 'horizontal',
                                align: 'center',
                                verticalAlign: 'top',
                                borderWidth: 0,
                            },
                            series: data,
                            credits: {
                                enabled: false
                            }
                        });
                    }, 0);
                }
            }
        }).show();
    },
    chartInit: function (domId, title, data) {
        $('#' + domId).highcharts({
            title: {
                text: ''
            },
            // chart: {
            //     marginLeft: 40
            // },
            xAxis: {
                categories: ['6月', '7月', '8月', '9月', '10月', '11月', '12月', '1月', '2月', '3月', '4月', '5月']
            },
            yAxis: {
                title: {
                    text: '水量/亿m³'
                },
                plotLines: [{
                    value: 0,
                    width: 1,
                    color: '#808080'
                }]
            },
            tooltip: {
                valueSuffix: '亿m³'
            },
            legend: {
                layout: 'horizontal',
                align: 'center',
                verticalAlign: 'top',
                borderWidth: 0,
            },
            series: data,
            credits: {
                enabled: false
            }
        });
    },
    changeType: function (_this) {
        if (!_this._visited) {
            _this._visited = true;
            _this.getEl().addClass("x-btn-visited");
        }
    }
})
